/***********************************************************************
 * Module:  ControlTaskController.java
 * Author:  Administrator
 * Purpose: Defines the Class ControlTaskController
 ***********************************************************************/

package ishitong.rvims.control.controller;

import ishitong.rvims.control.service.ControlTaskService;
import org.springframework.web.servlet.ModelAndView;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import ishitong.core.common.SQLSelectWhere;
import ishitong.rvims.domain.control.ControlVehicle;
import ishitong.rvims.domain.control.ControlPoint;
import ishitong.rvims.domain.control.ControlType;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import ishitong.rvims.domain.control.ControlTask;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import ishitong.core.common.ActionController;

/** @pdOid ba19ea2c-c4d2-4760-aa2e-1769ba18a844 */
@Controller
public class ControlTaskController extends ActionController {
   /** @pdOid cd00c5aa-c7ec-4543-bba4-e175d5169952
       @pdRoleInfo migr=yes name=ControlTaskService assc=association7 */
   @Autowired
   private ControlTaskService controlTaskService;
   
   /** @param request 
    * @param response
    * @exception Exception
    * @pdOid 90fa80bf-3100-4bc3-8fa0-1d5f03fc2ced */
   @RequestMapping(value = "/ajaxShowControlTaskDialog.do")
   public ModelAndView handleAjaxShowControlTaskDialog(HttpServletRequest request, HttpServletResponse response) throws Exception {
    return new ModelAndView("control/ControlTaskDialog");
   }
   
   /** @param request 
    * @param response 
    * @param sQLSelectWhere
    * @exception Exception
    * @pdOid d2df8b18-4195-4994-835a-4580e8fb6297 */
   @RequestMapping(value = "/ajaxFindControlTaskListForSelect.do")
   public ModelAndView handleAjaxFindControlTaskListForSelect(HttpServletRequest request, HttpServletResponse response, SQLSelectWhere sQLSelectWhere) throws Exception {
    try {
    		Map<String, Object> model = new HashMap<String, Object>();
    		List<ControlTask> listControlTaskLeft = controlTaskService.findControlTaskList(sQLSelectWhere);
    		model.put("listControlTaskLeft", listControlTaskLeft);
    		return new ModelAndView("control/ControlTaskListForSelect", model);
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
      return null;
   }
   
   /** @param request 
    * @param response
    * @exception Exception
    * @pdOid 6b6da3ab-aa0f-4566-ad21-d54c2d8c699d */
   @RequestMapping(value = "/showControlTaskSearch.do")
   public ModelAndView handleShowControlTaskSearch(HttpServletRequest request, HttpServletResponse response) throws Exception {
    return new ModelAndView("control/ControlTaskSearch");
   }
   
   /** @param request 
    * @param response 
    * @param sQLSelectWhere
    * @exception Exception
    * @pdOid cfb9f7a4-1e99-4b83-bb2e-4dfb652b84a6 */
   @RequestMapping(value = "/ajaxControlTaskSearchList.do")
   public ModelAndView handleAjaxControlTaskSearchList(HttpServletRequest request, HttpServletResponse response, SQLSelectWhere sQLSelectWhere) throws Exception {
    try {
    		Map<String, Object> model = new HashMap<String, Object>();
    		//sQLSelectWhere.setStrParam1("%"+sQLSelectWhere.getStrParam1() + "%");
    		//sQLSelectWhere.setStrParam1("%"+sQLSelectWhere.getStrParam1() + "%");
    		List<ControlTask> listControlTask = controlTaskService.findControlTaskList(sQLSelectWhere);
    		sQLSelectWhere.setRecordCount(controlTaskService.getControlTaskTotal(sQLSelectWhere));
    		model.put("listControlTask", listControlTask);
    		model.put("sQLSelectWhere", sQLSelectWhere);
    		return new ModelAndView("control/ControlTaskSearchList", model);
    	} catch (Exception e) {
    		e.printStackTrace();
    	}
      return null;
   }
   
   /** @param request 
    * @param response
    * @exception Exception
    * @pdOid ddf45917-77c1-463b-8926-8225bca8b26f */
   @RequestMapping(value = "/showControlTaskAdd.do")
   public ModelAndView handleShowControlTaskAdd(HttpServletRequest request, HttpServletResponse response) throws Exception {
    return new ModelAndView("control/ControlTaskEdit", null);
   }
   
   /** @param request 
    * @param response 
    * @param controlTaskId
    * @exception Exception
    * @pdOid 30854574-e736-4118-b7d8-a0595ebaf875 */
   @RequestMapping(value = "/showControlTaskEdit.do")
   public ModelAndView handleShowControlTaskEdit(HttpServletRequest request, HttpServletResponse response, String controlTaskId) throws Exception {
    		try {
     	Map<String, Object> model = new HashMap<String, Object>();
     	ControlTask controlTask = controlTaskService.getControlTaskById(controlTaskId);
     	model.put("controlTask", controlTask);
     	return new ModelAndView("control/ControlTaskEdit", model);
     } catch (Exception e) {
     	e.printStackTrace();
     }
     return null;
   }
   
   /** @param request 
    * @param response 
    * @param strBeginTime 
    * @param strEndTime 
    * @param controlTask
    * @exception Exception
    * @pdOid c77b86b2-3f94-4366-bc4d-f3d6fe1e3b61 */
   @RequestMapping(value = "/saveControlTask.do")
   public ModelAndView handleSaveControlTask(HttpServletRequest request, HttpServletResponse response, String strBeginTime, String strEndTime, ControlTask controlTask) throws Exception {
    try {
     controlTask.setBeginTime(SQLSelectWhere.StringToDate(strBeginTime, null));
     controlTask.setEndTime(SQLSelectWhere.StringToDate(strEndTime, null));
     	controlTaskService.saveControlTask(controlTask);
     	return new ModelAndView("redirect:showControlTaskSearch.do");
     } catch (Exception e) {
     	e.printStackTrace();
     }
      return null;
   }
   
   /** @param request 
    * @param response 
    * @param controlTaskId
    * @exception Exception
    * @pdOid 4ce9984c-8caf-4915-a5bd-05e5a60cd0eb */
   @RequestMapping(value = "/showControlTaskView.do")
   public ModelAndView handleShowControlTaskView(HttpServletRequest request, HttpServletResponse response, String controlTaskId) throws Exception {
   try {
      	Map<String, Object> model = new HashMap<String, Object>();
      	ControlTask controlTask = controlTaskService.getControlTaskById(controlTaskId);
      	model.put("controlTask", controlTask);
      	return new ModelAndView("control/ControlTaskView", model);
      } catch (Exception e) {
      	e.printStackTrace();
      }
      return null;
    }
   
   /** @param request 
    * @param response 
    * @param controlTaskIds
    * @exception Exception
    * @pdOid 805961d8-9904-48aa-8a7a-f6fe14f0bfc0 */
   @RequestMapping(value = "/ajaxDeleteControlTaskByIds.do")
   public String handleAjaxDeleteControlTaskByIds(HttpServletRequest request, HttpServletResponse response, String controlTaskIds) throws Exception {
    try {
     	controlTaskService.deleteControlTaskByIds(controlTaskIds);
        return null;
     } catch (Exception e) {
     	e.printStackTrace();
     } 	   
      return null;
   }
   
   /** @param request 
    * @param response 
    * @param controlTaskIds 
    * @param isUsing
    * @exception Exception
    * @pdOid 6a16df0c-5389-4da7-90da-1dfa98c6e4ae */
   @RequestMapping(value = "/ajaxUseControlTaskState.do")
   public String handleAjaxUseControlTaskState(HttpServletRequest request, HttpServletResponse response, String controlTaskIds, String isUsing) throws Exception {
    try {
     	controlTaskService.setControlTaskUseState(controlTaskIds,isUsing);
        return null;
     } catch (Exception e) {
     	e.printStackTrace();
     } 	
      return null;
   }

}